package tcp;

import java.io.IOException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-26
 * Time: 20:47
 */

public class TcpDictServer extends TcpThreadPoolServer{
    private HashMap<String,String> dict = new HashMap<>();

    public TcpDictServer(int port) throws IOException {
        super(port);

        dict.put("cat","小猫");
        dict.put("dog","小狗");
        dict.put("pig","小猪");
    }

    @Override
    public String process(String request) {

        //getOrDefault如果有对应的key 返回key的val值 否则返回默认值
        return dict.getOrDefault(request,"当前的次无法翻译");
    }

    public static void main(String[] args) throws IOException {
        TcpDictServer dictServer = new TcpDictServer(9090);
        dictServer.start();
    }
}
